<html>
<head><meta charset="utf-8"><title>disable .got section in ELF object file · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html">disable .got section in ELF object file</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148659364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148659364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148659364">(Nov 27 2018 at 18:53)</a>:</h4>
<p>(First time using zulip, I was directed here by <span class="user-mention" data-user-id="123586">@nagisa</span>  from #rustc IRC, so lmk if I've done something wrong. )</p>
<p>How do I instruct rustc to not emit code that uses GOT-based relocations? </p>
<p>I have a large OS project that was previously using rustc 1.27.0, and by using the <code>code-model=large</code>, I was able to get it to never emit GOT-based relocations, and there wasn't even a <code>.got</code> or <code>.got.plt</code> section. I don't want the object file to contain any relocation entries like <code>R_X86_64_GOTPC64</code>, <code>R_X86_64_GOT64</code>, <code>R_X86_64_GOTOFF64</code>. <br>
I just upgraded to rustc 1.32.0 and it now uses the <code>.got</code> no matter what I do.  Disabling pic, pie, or plt don't seem to be doing the trick. Any tips? </p>
<p>Thanks!</p>



<a name="148659878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148659878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148659878">(Nov 27 2018 at 19:02)</a>:</h4>
<p>Do you know what symbols <em>do</em> emit these relocations?</p>



<a name="148659949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148659949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148659949">(Nov 27 2018 at 19:02)</a>:</h4>
<p>Also are you specifying <code>-Crelocation-model=static</code>?</p>



<a name="148660218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660218">(Nov 27 2018 at 19:07)</a>:</h4>
<p>looking at the output of <code>readelf</code>, it appears that <em>every</em> symbol is now using a GOT-based relocation type</p>



<a name="148660271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660271">(Nov 27 2018 at 19:08)</a>:</h4>
<p>i wasn't using a static relocation model, no.</p>



<a name="148660794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660794">(Nov 27 2018 at 19:17)</a>:</h4>
<p>… does it work with static relocation model?</p>



<a name="148660858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660858">(Nov 27 2018 at 19:18)</a>:</h4>
<p>Just tried the static relocation model -- it does indeed remove the .got section, but then it also causes other symbols to be absent from other crates' object files. <br>
The issue here is that I'm dynamically loading &amp; linking many object files (one obj file per crate in my project), and the static relocation model seems to cause some symbols to no longer be present in those object files. I'm looking into it now.</p>



<a name="148660874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660874">(Nov 27 2018 at 19:18)</a>:</h4>
<p>is there somewhere i can read more about the static relocation model? I didn't need to specify that before, when using rustc 1.27.0</p>



<a name="148660970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148660970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148660970">(Nov 27 2018 at 19:20)</a>:</h4>
<p>static relocation model is exactly what it says on the tin: it generates code without any relocations (what GOT is). The default model is not <code>static</code>, so it seems more like an accident/lucky coincidence that it did what you expected before</p>



<a name="148661046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148661046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148661046">(Nov 27 2018 at 19:21)</a>:</h4>
<p>i see, thanks. Yeah, it may have been a lucky coincidence before.</p>



<a name="148661142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148661142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148661142">(Nov 27 2018 at 19:23)</a>:</h4>
<p>Does the static relocation model <em>only</em> allow global/absolute address relocation types, or does it still allow PC-relative relocation types to be used? My previous object files on 1.27.0 contained PC-relative relo types, but I don't seen any now.</p>



<a name="148661281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148661281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148661281">(Nov 27 2018 at 19:25)</a>:</h4>
<p>honestly, not sure <span class="emoji emoji-1f642" title="slight smile">:slight_smile:</span></p>



<a name="148661325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148661325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148661325">(Nov 27 2018 at 19:25)</a>:</h4>
<p>you might want to try other options from <code>-Crelocation-model=help</code> as well to see if the stuff starts working with any of them</p>



<a name="148661410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148661410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148661410">(Nov 27 2018 at 19:26)</a>:</h4>
<p>ok, np. I did try a variety of relocation models yesterday, but they didn't seem to work. I'll go back and review them further. <br>
Thanks a lot in any case!</p>



<a name="148662091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148662091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148662091">(Nov 27 2018 at 19:37)</a>:</h4>
<p>I wonder if some LLVM change caused the large code model option to no longer take precedence over the  PIC relocation model option. From the docs, I would expect that if the large code model  option was given, then LLVM would be forced to use absolute relo types because it can't assume that relo sources are nearby the target PC....</p>



<a name="148663006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148663006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148663006">(Nov 27 2018 at 19:51)</a>:</h4>
<p>code model and relocation model are two independent options</p>



<a name="148663255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/disable%20.got%20section%20in%20ELF%20object%20file/near/148663255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kevin Boos <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/disable.20.2Egot.20section.20in.20ELF.20object.20file.html#148663255">(Nov 27 2018 at 19:55)</a>:</h4>
<p>ah, ok, in that case it's probably down to what you suggested before, a lucky coincidence in which specifying only the large code model resulted in no GOT-based relo entries.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>